package com.lams.service.archive.impl;

import static com.lams.util.ViewParamsUtil.getParam;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import com.lams.jdbc.QueryUtils;
import com.lams.service.BaseFacade;
import com.lams.service.archive.ITeacherFacade;
import com.lams.util.IdFactory;
import com.lams.util.ResultEntity;

public class TeacherFacade extends BaseFacade implements ITeacherFacade {
	private String queryTeacher;
	private String insertTeacher;
	private String updateTeacher;
	private String deleteTeacher;
	private static final String COLUMN_KEY = "TEACHER_ID";
	private static final String TABLE_NAME = "C_TEACHER";

	/* (non-Javadoc)
	 * @see com.lams.service.archive.impl.ITeacherFacade#queryTeacher(int, int, java.util.Map)
	 */
	@Override
	public ResultEntity queryTeacher(int start, int limit, Map params) {
		String sql = QueryUtils.getSqlBySqlCode(queryTeacher, params);
		ResultEntity result = new ResultEntity(QueryUtils.executeQuery(start,
				limit, sql), QueryUtils.getTotalCount(sql));
		return result;
	}

	/* (non-Javadoc)
	 * @see com.lams.service.archive.impl.ITeacherFacade#saveOrUpdate(java.util.Map)
	 */
	@Override
	public ResultEntity saveOrUpdate(Map params){
		String school_id = getParam(COLUMN_KEY);
		String sql = "";
		if (school_id == null || school_id.trim().equals("")) {
			params.put(COLUMN_KEY, IdFactory.getNextNav(TABLE_NAME, COLUMN_KEY));
			sql = QueryUtils.getSqlBySqlCode(insertTeacher, params);
		}else {
			sql = QueryUtils.getSqlBySqlCode(updateTeacher, params);
		}
		ResultEntity result = new ResultEntity();
		try {
			super.getDao().executeUpdate(sql);
			result.setSuccess(true);
			result.setMessage("保存成功");
		} catch (SQLException e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMessage("保存失败");
		}
		return result;
	}
	/* (non-Javadoc)
	 * @see com.lams.service.archive.impl.ITeacherFacade#delete(java.lang.String)
	 */
	@Override
	public boolean delete(String teacher_id){
		Map params = new HashMap();
		params.put(COLUMN_KEY, teacher_id);
		try {
			super.getDao().executeUpdate(QueryUtils.getSqlBySqlCode(deleteTeacher, params));
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}

	public void setQueryTeacher(String queryTeacher) {
		this.queryTeacher = queryTeacher;
	}

	public void setInsertTeacher(String insertTeacher) {
		this.insertTeacher = insertTeacher;
	}

	public void setUpdateTeacher(String updateTeacher) {
		this.updateTeacher = updateTeacher;
	}

	public void setDeleteTeacher(String deleteTeacher) {
		this.deleteTeacher = deleteTeacher;
	}
	
	
}
